#include <stdio.h>
void exchange(int* a, int* b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}
int main()
{
	int a[20] = { 0 }, b[20] = { 0 }, c[20] = { 0 };
	int i = 0, j = 0, m = 0, n = 0,x = 0;
	scanf("%d", &m);
	for (i = 0; i < m; i++)
	{
		scanf("%d", &a[i]);
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &b[i]);
	}
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (a[i] == b[j])
			{
				c[x]=a[i];
				x++;
			}
		}

	}
	for (i = 0; i < x; i++)
	{
		for (j = 0;j < x - i - 1;j++)
		{
			if (c[j] < c[j + 1])
			{
				exchange(&c[j], &c[j + 1]);
			}
		}
	}
	for (i = 0; i < x; i++)
	{
		printf("%d", c[i]);
	}
	return 0;
}
